﻿var test;

function getA_Value(el) {
    return el.attributes[1].nodeValue;
}

const routerInfo = {
    "TeacherManager": '/Teacher',
    "StudentManager": "/Student",
    "ClassManager": '/Class_',
    "CourseManager": '/Course',
    "PJRelease": '/Evaluating',
    "PJManager": '/Evaluating/Manager',
    "Record": '/Record',
    "QuestionManager":'/Question'
}

var tabindex = [];

//JavaScript代码区域
layui.use(['element', 'jquery'], function () {
    var element = layui.element;
    var $ = layui.jquery;

    // tabs数组 重复直接跳转
    let tabList = [];
    // nav数组
    let navList = [];
    let temp = document.querySelectorAll('.mynav');


    temp.forEach(r => navList.push(r.parentNode));

    // 清除Nav选中
    function ClearSelect() {
        $('.mynav').parent().removeClass("layui-this");
    }

    // 监听tab  给Nav添加选中
    element.on('tab(mytab)',
        function (data) {
            ClearSelect();
            let needNav = temp.forEach(r => {
                if ($(r).attr('value') == $(this).attr("lay-id")) {
                    $(r).parent().addClass('layui-this');
                }
            });
        });

    // 监听导航切换
    element.on('nav(mynav)',
        ({ context }) => {
            let tabid = $(context).attr('value');
            if (tabList.filter(r => r.layid == tabid).length == 1) {
                element.tabChange('mytab', tabid);
                return;
            }
            element.tabAdd('mytab',
                {
                    title: context.innerText,
                    content:
                        `<iframe tabid="${tabid}" src="${routerInfo[tabid]}" width="99%" height="99%" style="border: 0;"></iframe>`,
                    id: tabid
                });
            element.tabChange('mytab', tabid);
            // 保存到数组中
            tabindex.push(tabid);
            tabList.push({
                layid: tabid
            });
        });

    // 监听tab关闭
    element.on('tabDelete(mytab)',
        function (data) {
            let tab_id = tabindex.splice(data.index, 1)[0];
            tabList = tabList.filter(t => t.layid != tab_id);
        });
});